package eco.lamp.bl;

import java.text.MessageFormat;

import eco.lamp.R;

import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;

public class LampItem implements Parcelable {

	int mLampType = 0;
	int mPower = 0;
	int mNumber = 0;

	int getLampType() {
		return mLampType;
	}

	public int getNumber() {
		return mNumber;
	}

	public void setNumber(int number) {
		mNumber = number;
	}

	public int getSumPower() {
		return mPower * mNumber;
	}

	public static LampItem createINCLamp(int power, int number) {
		return new LampItem(LampUtil.LAMP_TYPE_INCADESCENT, power, number);
	}

	public static LampItem createFLRLamp(int power, int number) {
		return new LampItem(LampUtil.LAMP_TYPE_FLUORESCENT, power, number);
	}

	public static LampItem createLEDLamp(int power, int number) {
		return new LampItem(LampUtil.LAMP_TYPE_LED, power, number);
	}

	public LampItem(int lampType, int power, int number) {
		mLampType = lampType;
		mPower = power;
		mNumber = number;
	}

	public LampItem(Parcel in) {
		mLampType = in.readInt();
		mPower = in.readInt();
		mNumber = in.readInt();
	}

	public String toString(Resources r) {
		String template = "{0} X {1} ({2, number, 0} {3}, {4, number, 0} {5}, {6, number, 0} {7} )";
		String lampType = LampUtil.getLampTypeName(mLampType, r);
		String result = MessageFormat.format(template, mNumber, lampType, mPower, r
				.getString(R.string.strWt), getOutput(), r
				.getString(R.string.strLm), getLife(), r
				.getString(R.string.strHr));
		return result;
	}

	public int getSumOutput() {
		int result = LampUtil.getOutput(mLampType, mPower) * mNumber;
		return result;
	}

	public int getOutput() {
		int result = LampUtil.getOutput(mLampType, mPower);
		return result;
	}

	public int getPower() {
		return mPower;
	}

	public void setPower(int power) {
		mPower = power;
	}

	public int getLife() {
		int result = LampUtil.getLife(mLampType);
		return result;
	}

	public int describeContents() {
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(mLampType);
		dest.writeInt(mPower);
		dest.writeInt(mNumber);
	}

	public static final Parcelable.Creator<LampItem> CREATOR = new Parcelable.Creator<LampItem>() {
		public LampItem createFromParcel(Parcel in) {
			return new LampItem(in);
		}

		public LampItem[] newArray(int size) {
			return new LampItem[size];
		}
	};
}
